package com.demo.sdcard;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class DealPic {
	public static void makeDir(){
		String sdState = android.os.Environment.getExternalStorageState();
		if (!sdState.equals(android.os.Environment.MEDIA_MOUNTED)) {
			return;
		}
		File SDFile = android.os.Environment.getExternalStorageDirectory();
		File destDir = new File(SDFile.getAbsolutePath()+"/TheFourth/");
		if (!destDir.exists()) {
			destDir.mkdirs();
		}
	}
	
	public static void saveBitmap(String bitName, Bitmap mBitmap) throws IOException {
		String sdState = android.os.Environment.getExternalStorageState();
		if (!sdState.equals(android.os.Environment.MEDIA_MOUNTED)) {
			return;
		}

		File SDFile = android.os.Environment.getExternalStorageDirectory();
		File myFile = new File(SDFile.getAbsolutePath()+"/TheFourth/"+bitName);
        myFile.createNewFile();
        FileOutputStream fOut = null;
        try {
                fOut = new FileOutputStream(myFile);
        } catch (FileNotFoundException e) {
                e.printStackTrace();
        }
        mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
        try{
    		fOut.flush();
    		fOut.close();
	    } catch (IOException e) {
	    	e.printStackTrace();
	    }
	}
	
	public static Bitmap getBitmap(String bitName){
		String sdState = android.os.Environment.getExternalStorageState();
		if (!sdState.equals(android.os.Environment.MEDIA_MOUNTED)) {
			return null;
		}
		File SDFile = android.os.Environment.getExternalStorageDirectory();
		Bitmap bit = BitmapFactory.decodeFile(SDFile.getAbsolutePath()+"/TheFourth/"+bitName);
		return bit;
	}
}
